<template>
  <div class="contaier">
    <div class="weui_cells_title">请登录：</div>
    <div class="weui_cells weui_cells_form">
      <div class="weui_cell" :class="{'weui_cell_warn' : invalidBindingNum}">
        <div class="weui_cell_hd">
          <label class="weui_label">住院号</label>
        </div>
        <div class="weui_cell_bd weui_cell_primary">
          <input class="weui_input" v-model="bindingNum" style="padding-left: 15px;" type="tel" placeholder="请输入住院号">
        </div>
        <div class="weui_cell_ft">
          <i class="weui_icon_warn"></i>
        </div>
      </div>
      <div class="weui_cell" :class="{'weui_cell_warn' : invalidBindingName}">
        <div class="weui_cell_hd">
          <label class="weui_label">姓名</label>
        </div>
        <div class="weui_cell_bd weui_cell_primary">
          <input class="weui_input" v-model="bindingName" style="padding-left: 15px;" type="text" placeholder="请输入姓名">
        </div>
        <div class="weui_cell_ft">
          <i class="weui_icon_warn"></i>
        </div>
      </div>
    </div>
    <a @click="doBinding" href="javascript:;" style="margin:5px 8px;" class="weui_btn weui_btn_primary">确认</a>
  </div>
</template>
<script>
  import _ from 'underscore'
  export default {
    name: 'DeprtessionCardView',
    data: function () {
      return {
        bindingNum: '',
        bindingName: '',
        invalidBindingNum: false,
        invalidBindingName: false,
        clinPatientInfo: []
      }
    },
    methods: {
      doBinding: function () {
        if (!this.checkUserInput()) {
          return
        }
        var self = this
        this.$ajax.get('GetMaternalInfo', 'PostpartumDepression', {
          cardNo: this.bindingNum,
          name: this.bindingName
        }).then(function (data) {
          self.clinPatientInfo = _.map(data.ClinPatientInfo, function (val) {
            return {
              name: val.Name,
              age: val.Age,
              IDCard: val.IDCard,
              cardNo: val.CardNo,
              pregnancyDT: val.PregnancyDT,
              childbirthDT: val.ChildbirthDT
            }
          })
        })
        this.$router.go({ name: 'depressionDetail', query: { name: this.clinPatientInfo.name, age: this.clinPatientInfo.age, IDCard: this.clinPatientInfo.IDCard, cardNo: this.clinPatientInfo.cardNo, pregnancyDT: this.clinPatientInfo.pregnancyDT, childbirthDT: this.clinPatientInfo.childbirthDT } })
      },
      checkUserInput: function () {
        if (this.bindingNum === '') {
          this.invalidBindingNum = true
          this.showCommonToast({ msg: '请输入住院号' })
          return false
        }
        if (this.bindingName === '') {
          this.invalidBindingName = true
          this.showCommonToast({ msg: '请输入姓名' })
          return false
        }
        return true
      }
    }
  }
</script>
